{% extends 'news/base.html' %}

{% block titleBlock %}
    首页
{% endblock %}

{% block scriptBlock %}
    <script type="text/javascript" src="../../static/news/js/index.js"></script>
 <script type="text/javascript" src="../../static/news/js/jquery-1.12.4.min.js"></script>
{% endblock %}

{% block categoryBlock %}
    <ul class="menu fl">
        {% for category in data.categories %}
            <li class="{% if loop.index0 == 0 %}active{% endif %}" data-cid="{{ category.id }}"><a
                    href="javascript:;">{{ category.name }}</a></li>
        {% endfor %}
        <div style="margin-left: 400px;margin-top: 20px;">

            <button type="submit" value="搜索" id="search_btn" style="display:inline-block;float: right;border: 1px solid #ccc;height: 25px;border-radius: 5px">搜索</button>
            <input type="text" name="search" id="search" placeholder="输入标题关键字搜索" style="width:140px;height: 23px;border: 1px solid #ccc">
        </div>
    </ul>
{% endblock %}

{% block contentBlock %}
    <ul class="list_con fl">

    </ul>

{% endblock %}

{% block userBlock %}
<script>
    $('#search_btn').click(function(){
        var search=$('#search').val()
        console.log(search)
        $.ajax({
        url:'/news_list?search='+search,//接口地址
        type:'GET',//传值方式

        success:function(resp){
            $(".list_con").html("")
            for (var i = 0; i < resp.data.news_dict_li.length; i++) {
            var news = resp.data.news_dict_li[i]
            var content = '<li>'
            content += '<a href="/news/' + news.id + '" class="news_pic fl"><img src="' + news.index_image_url + '?imageView2/1/w/170/h/170"></a>'
            content += '<a href="/news/' + news.id + '" class="news_title fl">' + news.title + '</a>'
            content += '<a href="/news/' + news.id + '" class="news_detail fl">' + news.digest + '</a>'
            content += '<div class="author_info fl">'
            content += '<div class="source fl">来源：' + news.source + '</div>'
            content += '<div class="time fl">' + news.create_time + '</div>'
            content += '</div>'
            content += '</li>'
            $(".list_con").append(content)
        }

    }
    })
    })
</script>
{% endblock %}

